import validateRule from '@/utils/validateRule'
import { SALE_ORDER_TYPE } from '@/model/type'

export const dataTypeList = [
  {
    label: '全部销售单',
    name: '-1'
  },
  {
    label: '我的销售单',
    name: '1'
  },
  {
    label: '下属销售单',
    name: '2'
  }
]
export const dateTypeList = [
  {
    name: '签单日期',
    value: '1'
  },
  {
    name: '退款日期',
    value: '2'
  }
]

export const uploadStatusList = [ // 附件状态
  {
    name: '全部',
    value: '-1'
  },
  {
    name: '有附件',
    value: '1'
  },
  {
    name: '无附件',
    value: '2'
  }
]
export const receiptStatusList = [
  {
    name: '全部',
    value: '-1'
  },
  {
    name: '已回执',
    value: '1'
  },
  {
    name: '未回执',
    value: '2'
  }
]
export const columns = ctx => {
  // 已通过
  let hideOne = ctx.searchForm.checkStatus === '3'
  // 销售单类型
  let isMySole = ctx.searchForm.dataType === '1'
  return [
    {
      prop:
        ctx.searchForm.checkStatus === '3' ||
        ctx.searchForm.checkStatus === '0'
          ? 'orderNo'
          : 'code',
      label: '销售单号',
      headCheck: '1',
      minWidth: 200,
      toolTip: true
    },
    {
      label: '销售单类型',
      headCheck: '1',
      minWidth: 120,
      render: (h, row) => {
        return [
          <el-tag
            size="medium"
            type={SALE_ORDER_TYPE[row.saleTypeName] || 'primary'}
          >
            {row.saleTypeName || '-'}
          </el-tag>
        ]
      }
    },
    {
      prop: 'productTypeName',
      label: '产品类型',
      headCheck: '1',
      minWidth: 120
    },
    {
      prop: 'name',
      label: '销售单名称',
      headCheck: '1',
      minWidth: 200,
      toolTip: true
    },
    {
      hide: !hideOne,
      prop: 'customerName',
      label: '关联客户',
      headCheck: '1',
      minWidth: 200,
      toolTip: true
    },
    {
      hide: !hideOne,
      prop: 'checkStatusName',
      label: '审批状态',
      headCheck: '1',
      minWidth: 120
    },
    {
      hide: !hideOne,
      prop: 'status',
      label: '订单状态',
      headCheck: '1',
      minWidth: 150,
      render: (h, row) => {
        let typeList = {
          1: 'success',
          2: 'danger',
          3: 'warning',
          4: 'info',
          5: 'success'
        }
        return [
          <el-tag size="medium" type={typeList[+row.status]}>
            {row.statusName}
          </el-tag>
        ]
      }
    },
    {
      hide: !hideOne,
      prop: 'uploadStatusName',
      label: '附件状态',
      headCheck: '0',
      minWidth: 120
    },
    {
      hide: !hideOne,
      prop: 'signDate',
      label: '签单日期',
      headCheck: '1',
      minWidth: 160
    },
    {
      hide: !hideOne,
      prop: 'saleTotalPrice',
      label: '销售单总额',
      headCheck: '1',
      minWidth: 120
    },
    {
      hide: !hideOne,
      prop: 'payMoney',
      label: '已回款金额',
      headCheck: '1',
      minWidth: 120
    },
    {
      hide: !hideOne,
      prop: 'refundTotalPrice',
      label: '退款金额',
      headCheck: '1',
      minWidth: 100
    },
    {
      hide: !hideOne,
      prop: 'refundNumber',
      label: '退货数量',
      headCheck: '1',
      minWidth: 100
    },
    {
      hide: !hideOne,
      prop: 'actualSaleTotalPrice',
      label: '实际应收',
      headCheck: '1',
      minWidth: 100
    },
    {
      hide: !hideOne,
      prop: 'residueSaleTotalPrice',
      label: '剩余应收',
      headCheck: '1',
      minWidth: 100
    },
    {
      hide: !hideOne,
      prop: 'companyName',
      label: '所属公司',
      headCheck: '1',
      minWidth: 100,
      toolTip: true
    },
    {
      hide: !hideOne,
      prop: 'activeDay',
      label: '距激活日期天数',
      headCheck: '0',
      minWidth: 160
    },
    {
      hide: !hideOne,
      prop: 'proportionPrice',
      label: '预估绩效提成',
      headCheck: '0',
      minWidth: 150
    },
    {
      hide: !hideOne,
      prop: 'actualProportionPrice',
      label: '实际绩效提成',
      headCheck: '0',
      minWidth: 150
    },
    {
      hide: !hideOne,
      prop: 'invoiceType',
      label: '发票类型',
      headCheck: '0',
      minWidth: 150
    },
    {
      hide: !hideOne,
      prop: 'settlementType',
      label: '结算方式',
      headCheck: '0',
      minWidth: 120
    },
    {
      hide: !hideOne,
      prop: 'invoiceMain',
      label: '开票主体',
      headCheck: '0',
      minWidth: 150,
      toolTip: true
    },
    {
      hide: !hideOne,
      prop: 'companyType',
      label: '我方信息',
      headCheck: '0',
      minWidth: 150
    },
    {
      hide: !hideOne,
      prop: 'contractType',
      label: '合同形式',
      headCheck: '0',
      minWidth: 150
    },
    {
      prop: 'operator',
      label: '归属业务员',
      headCheck: '0',
      minWidth: 200,
      toolTip: true
    },
    {
      hide: !hideOne,
      prop: 'apartmentName',
      label: '归属部门',
      headCheck: '0',
      minWidth: 200,
      toolTip: true
    },
    {
      hide: !hideOne,
      prop: 'remark',
      label: '备注',
      headCheck: '0',
      minWidth: 200,
      toolTip: true
    },
    {
      hide: !hideOne,
      prop: 'payDate',
      label: '计划回款日期',
      headCheck: '0',
      minWidth: 150
    },
    {
      hide: !hideOne,
      prop: 'overdueDay',
      label: '逾期天数(天)',
      headCheck: '0',
      minWidth: 150
    },
    {
      hide: !hideOne,
      prop: 'productName',
      label: '产品名称',
      headCheck: '0',
      minWidth: 150,
      toolTip: true
    },
    {
      hide: !hideOne,
      prop: 'productCode',
      label: '产品编号',
      headCheck: '0',
      minWidth: 150,
      toolTip: true
    },
    {
      hide: !hideOne,
      prop: 'number',
      label: '销售数量',
      headCheck: '0',
      minWidth: 150
    },
    {
      hide: !hideOne,
      prop: 'saleType',
      label: '售货方式',
      headCheck: '0',
      minWidth: 150
    },
    {
      hide: !hideOne,
      prop: 'parValue',
      label: '产品面值',
      headCheck: '0',
      minWidth: 150,
      toolTip: true
    },
    {
      hide: !hideOne,
      prop: 'discountValue',
      label: '优惠面值',
      headCheck: '0',
      minWidth: 150,
      toolTip: true
    },
    {
      hide: !hideOne,
      prop: 'salePrice',
      label: '销售单价',
      headCheck: '0',
      minWidth: 150
    },
    {
      hide: !hideOne,
      prop: 'goodsName',
      label: '商品名称',
      headCheck: '0',
      minWidth: 150
    },
    {
      hide: !hideOne,
      label: '提成比例',
      headCheck: '0',
      prop: 'proportion',
      minWidth: 150
      /* render: (h, row) => {
        return <span>{row.proportion + '%'}</span>
      } */
    },
    {
      hide: hideOne,
      prop: 'updateTime',
      label: '修改时间',
      headCheck: '0',
      minWidth: 200
    },
    {
      hide: !hideOne,
      prop: 'payStatus',
      label: '回款状态',
      headCheck: '0',
      minWidth: 120,
      render: (h, row) => {
        let typeList = {
          1: 'info',
          2: 'warning',
          3: 'success',
          4: 'danger'
        }
        return [
          <el-tag type={typeList[+row.payStatus]}>{row.payStatusName}</el-tag>
        ]
      }
    },
    {
      hide: !hideOne,
      prop: 'invoicePrice',
      label: '已开票金额',
      headCheck: '0',
      minWidth: 150
    },
    {
      hide: !hideOne,
      prop: 'cardSaleScale',
      label: '销售折扣',
      headCheck: '0',
      minWidth: 150,
      render: (h, row) => {
        return <span>{row.cardSaleScale + '%'}</span>
      }
    },
    {
      hide: !hideOne,
      prop: 'approveTime',
      label: '审批通过时间',
      headCheck: '0',
      minWidth: 150
    },
    {
      label: '操作',
      headFixed: '1',
      fixed: 'right',
      minWidth: 240,
      render: (h, row, index) => {
        let isAppro =
          row.checkStatus === '2' ||
          row.checkStatus === '4' ||
          row.checkStatus === '0'
        return [
          <el-button type="text" v-show={isMySole} onClick={() => ctx.onCopy(row)}>
            复制
          </el-button>,
          <el-button type="text" onClick={() => ctx.onDetail(row)}>
            详情
          </el-button>,
          <el-button
            type="text"
            onClick={() => ctx.onEdit(row)}
            v-show={isAppro}
          >
            编辑
          </el-button>,
          <el-button
            type="text"
            onClick={() => ctx.onDelete(row)}
            v-show={isAppro}
          >
            删除
          </el-button>,
          <el-button
            type="text"
            onClick={() => ctx.onSubmit(row)}
            v-show={isAppro}
          >
            提交审批
          </el-button>,
          <el-button
            type="text"
            onClick={() => ctx.onReject(row)}
            v-show={row.checkStatus === '1'}
          >
            撤回审批
          </el-button>
        ]
      }
    }
  ]
}

export const contractTypeList = [
  {
    name: '三联单',
    value: '1'
  },
  {
    name: '纸质合同',
    value: '2'
  },
  {
    name: '电子合同',
    value: '3'
  }
]

export const companyTypeList = [
  {
    name: '福州爱来有限公司',
    value: '1'
  },
  {
    name: '福建中瑞心选科技有限责任公司',
    value: '2'
  }
]

export const settlementTypeList = [
  {
    name: '销售结算',
    value: '1'
  },
  {
    name: '绑定结算',
    value: '2'
  },
  {
    name: '兑换结算',
    value: '3'
  },
  {
    name: '周期结算',
    value: '4'
  }
]

export const invoiceTypeList = [
  {
    name: '福建增值税普通发票',
    value: '1'
  },
  {
    name: '福建增值税专用发票',
    value: '2'
  },
  {
    name: '福建增值税电子普通发票',
    value: '3'
  }
]

export const isInvoiceList = [
  {
    name: '申请开票',
    value: '1'
  },
  {
    name: '无需开票',
    value: '0'
  }
]

export const formRuleOne = (form) => {
  return {
    name: [
      {
        required: true,
        message: '请输入销售单名称',
        trigger: 'change'
      }
    ],
    contractType: [
      {
        required: true,
        message: '请选择合同形式',
        trigger: 'change'
      }
    ],
    customerId: [
      {
        required: true,
        message: '请选择销售的客户',
        trigger: 'change'
      }
    ],
    companyType: [
      {
        required: true,
        message: '请选择签约公司主体信息',
        trigger: 'change'
      }
    ],
    settlementType: [
      {
        required: true,
        message: '请选择结算方式',
        trigger: 'change'
      }
    ],
    signDate: [
      {
        required: true,
        message: '请选择签单日期',
        trigger: 'change'
      }
    ],
    isInvoice: [
      {
        required: true,
        message: '请选择是否开票',
        trigger: 'change'
      }
    ],
    invoiceType: [
      {
        required: true,
        message: '请选择发票类型',
        trigger: 'change'
      }
    ],
    companyId: [
      {
        required: true,
        message: '请选择所属公司',
        trigger: 'change'
      }
    ],
    businessScene: [
      {
        required: true,
        message: '请选择业务场景',
        trigger: 'change'
      }
    ],
    number: [
      {
        required: true,
        message: '请输入包场人数',
        trigger: 'change'
      }
    ],
    saleTotalPrice: [
      {
        required: true,
        message: '请输入销售单总价',
        trigger: 'change'
      }
    ],
    complaintType: [
      {
        required: true,
        message: '请选择客诉类型',
        trigger: 'change'
      }
    ],
    complaintRemark: [
      {
        required: true,
        message: '请填写备注信息',
        trigger: 'blur'
      }
    ],
    enclosureUrlName: [
      {
        required: form.type === '2' || form.type === '3',
        message: '请选择附件上传',
        trigger: 'change'
      }
    ],
    minSalePrice: [
      {
        required: true,
        message: '请输入产品最低销售单价',
        trigger: 'blur'
      },
      {
        validator: validateRule.isPositive
      }
    ],
    ruleProportion: [
      {
        required: true,
        message: '请输入提成比例',
        trigger: 'blur'
      },
      {
        validator: validateRule.isPositive
      }
    ]
  }
}

export const rulesCustomizePrice = [
  {
    label: 'unitPrice',
    rules: [
      {
        required: true,
        message: '请输入销售单价',
        trigger: 'blur'
      },
      {
        validator: validateRule.isPositive
      }
    ]
  },
  {
    label: 'num',
    rules: [
      {
        required: true,
        message: '请输入数量',
        trigger: 'blur'
      },
      {
        validator: validateRule.integer
      }
    ]
  },
  {
    label: 'totalPrice',
    rules: [
      {
        required: true,
        message: '请输入总额',
        trigger: 'blur'
      },
      {
        validator: validateRule.isPositive
      }
    ]
  }
]

export const formRuleTwo = {
  productId: [
    {
      required: true,
      message: '请选择关联产品',
      trigger: 'blur'
    }
  ],
  isCashDiff: [
    {
      required: true,
      message: '请选择是否开发现金补差',
      trigger: 'blur'
    }
  ],
  couponProductId: [
    {
      required: true,
      message: '请选择次卡绑定产品',
      trigger: 'blur'
    }
  ],
  saleType: [
    {
      required: true,
      message: '请选择售货方式',
      trigger: 'blur'
    }
  ],
  isGive: [
    {
      required: true,
      message: '请选择转赠配置',
      trigger: 'blur'
    }
  ],
  isUnbundling: [
    {
      required: true,
      message: '请选择解绑配置',
      trigger: 'blur'
    }
  ],
  isOpenRecharge: [
    {
      required: true,
      message: '请选择开放充值',
      trigger: 'blur'
    }
  ],
  saleScalePrice: [
    {
      required: true,
      message: '请填写销售比例',
      trigger: 'blur'
    },
    {
      validator: validateRule.isInteger
    }
  ],
  saleScalePoint: [
    {
      required: true,
      message: '请填写销售比例',
      trigger: 'blur'
    },
    {
      validator: validateRule.isInteger
    }
  ],
  consumptionScalePrice: [
    {
      required: true,
      message: '请填写消费比例',
      trigger: 'blur'
    },
    {
      validator: validateRule.isInteger
    }
  ],
  consumptionScalePoint: [
    {
      required: true,
      message: '请填写消费比例',
      trigger: 'blur'
    },
    {
      validator: validateRule.isInteger
    }
  ],
  isCustomize: [
    {
      required: true,
      message: '请选择点卡销售方式',
      trigger: 'blur'
    }
  ],
  salePrice: [
    {
      required: true,
      message: '请输入销售单价',
      trigger: 'blur'
    },
    {
      validator: validateRule.isPositive
    }
  ],
  couponPrice: [
    {
      required: true,
      message: '请输入券销售单价',
      trigger: 'blur'
    },
    {
      validator: validateRule.isPositive
    }
  ],
  couponNumber: [
    {
      required: true,
      message: '请输入单张次卡内含张数',
      trigger: 'blur'
    },
    {
      validator: validateRule.integer
    }
  ],
  parValue: [
    {
      required: true,
      message: '请输入产品面值',
      trigger: 'blur'
    }
  ],
  number: [
    {
      required: true,
      message: '请输入销售数量',
      trigger: 'blur'
    },
    {
      validator: validateRule.integer
    }
  ],
  computedTotal: [
    {
      required: true,
      message: '请输入销售单总额',
      trigger: 'blur'
    },
    {
      validator: validateRule.isPositive
    }
  ],
  productExpiredDays: [
    {
      required: true,
      message: '请匹配正确的有效天数',
      trigger: 'blur'
    }
  ],
  expiredType: [
    {
      required: true,
      message: '请选择有效期类型',
      trigger: 'blur'
    }
  ],
  startDate: [
    {
      required: true,
      message: '请选择有效期',
      trigger: 'blur'
    }
  ],
  floatDay: [
    {
      required: true,
      message: '请输入天数',
      trigger: 'blur'
    },
    {
      validator: validateRule.integer
    }
  ],
  floatUnit: [
    {
      required: true,
      message: '请选择周期单位',
      trigger: 'blur'
    }
  ],
  proportion: [
    {
      required: true,
      message: '请匹配正确的提成比例',
      trigger: 'blur'
    },
    {
      pattern: '^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$',
      message: '请输入最多包含2位小数的正数'
    }
  ],
  // proportionPrice: [
  //   {
  //     required: true,
  //     message: "请填写预估提成",
  //     trigger: "blur"
  //   }
  // ],
  remark: [
    {
      required: true,
      message: '请输入备注',
      trigger: 'blur'
    }
  ]
}

export const productColumns = context => {
  return [
    {
      hide: context.isMultiple,
      minWidth: 80,
      render: (h, row) => {
        return [
          <el-radio
            value={context.form.productId}
            on-input={val => {
              context.form.productId = val
            }}
            label={row.id}
            onchange={() => context.chooseRadio(row)}
            class="no-label"
          />
        ]
      }
    },
    {
      prop: 'productCode',
      label: '产品编号',
      minWidth: 120
    },
    {
      prop: 'name',
      label: '产品名称',
      minWidth: 120
    },
    {
      prop: 'typeName',
      label: '产品类型',
      minWidth: 120
    },
    {
      prop: 'businessTypeName',
      label: '业务类型',
      minWidth: 120
    },
    // {
    //   prop: 'practiceCostPrice',
    //   label: '产品成本',
    //   minWidth: 120
    // },
    {
      prop: 'parValue',
      label: '产品面值',
      minWidth: 120
    },
    {
      prop: 'apartmentName',
      label: '可售部门',
      minWidth: 120
    },
    {
      prop: 'exchangeRangeName',
      label: '兑换范围',
      minWidth: 120
    },
    {
      label: '操作',
      headFixed: '1',
      fixed: 'right',
      render: (h, row) => {
        return [
          <el-button
            type="text"
            onClick={() => {
              context.onDetail(row)
            }}
          >
            详情
          </el-button>
        ]
      }
    }
  ]
}

export const shiwuProductColumns = context => {
  return [
    {
      prop: 'productCode',
      label: '产品编号',
      minWidth: 120
    },
    {
      prop: 'name',
      label: '产品名称',
      minWidth: 120
    },
    {
      prop: 'specification',
      label: '规格',
      minWidth: 120
    },
    {
      prop: 'unit',
      label: '单位',
      minWidth: 120
    },
    {
      prop: 'apartmentList',
      label: '可售部门',
      minWidth: 120
    },
    {
      prop: 'minSalePrice',
      label: '最低销售单价',
      minWidth: 120
    },
    {
      prop: 'deliveryMoney',
      label: '运费',
      minWidth: 120
    },
    {
      label: '操作',
      headFixed: '1',
      fixed: 'right',
      render: (h, row) => {
        return [
          <el-button
            type="text"
            onClick={() => {
              context.onDetail(row)
            }}
          >
            详情
          </el-button>
        ]
      }
    }
  ]
}

export const saleTypeList = [
  {
    name: '纸质',
    value: '1'
  },
  {
    name: '电子',
    value: '2'
  }
]

export const unitList = [
  {
    name: '天',
    value: 'day'
  },
  {
    name: '月',
    value: 'month'
  },
  {
    name: '周',
    value: 'week'
  }
]

export const isCustomizeList = [
  {
    name: '统一金额',
    value: '0'
  }
  // {
  //   name: '自定义金额',
  //   value: '1'
  // }
]

export const customizePriceColumns = context => {
  return [
    {
      label: '自定义金额',
      minWidth: 100,
      render: (h, row, index) => {
        return [<span>金额{index + 1}</span>]
      }
    },
    {
      prop: '',
      label: '销售单价',
      minWidth: 100,
      render: (h, row) => {
        return [
          <zm-input
            value={row.unitPrice}
            on-input={val => {
              row.unitPrice = val
            }}
            class="w100"
          />,
          <span class="ml5">元</span>
        ]
      }
    },
    {
      label: '产品面值',
      minWidth: 100,
      render: (h, row, index) => {
        return [
          <span>
            内含{row.unitPrice}元,折合卡内点数{row.unitPoint}点
          </span>
        ]
      }
    },
    {
      prop: '',
      label: '数量',
      minWidth: 100,
      render: (h, row) => {
        return [
          <zm-input
            value={row.num}
            on-input={val => {
              row.num = val
            }}
            class="w100"
          />,
          <span class="ml5">张</span>
        ]
      }
    },
    {
      label: '总额',
      minWidth: 100,
      render: (h, row) => {
        return [
          <zm-input
            value={row.totalPrice}
            on-input={val => {
              row.totalPrice = val
            }}
            class="w100"
          />,
          <span class="ml5">元</span>
        ]
      }
    },
    {
      label: '操作',
      fixed: 'right',
      render: (h, row, index) => {
        return [
          <el-button type="text" onClick={() => context.addPrice(row)}>
            新增
          </el-button>,
          <el-button
            v-show={index > 0}
            type="text"
            onClick={() => context.deletePrice(index)}
          >
            删除
          </el-button>
        ]
      }
    }
  ]
}

// 业务场景下拉框
export const businessScenario = [
  {
    value: '',
    label: '请选择'
  },
  {
    value: '1',
    label: '运营'
  },
  {
    value: '2',
    label: '实物'
  },
  {
    value: '3',
    label: '营销'
  },
  {
    value: '4',
    label: '地推'
  }
]

// 方案类型
export const typeList = [
  {
    name: '根据销售单绑定卡券',
    value: '1'
  },
  {
    name: '根据会员支付订单数',
    value: '2'
  },
  {
    name: '根据会员购票数量',
    value: '3'
  }
]

// 方案信息
export const base = info => {
  return [
    { name: '方案ID', label: 'id' },
    { name: '方案名称', label: 'name' },
    { name: '有效期', label: 'timeTypeDes' },
    { name: '方案类型', label: 'typeDes' },
    // 如果 方案类型为1:根据销售单绑定卡券数量 则不显示 支付类型
    { hide: info.form.type.toString() === '1', name: '支付类型', label: 'payTypeDes' },
    { name: '触发场景', label: 'sceneDes' },
    { name: '使用产品', label: 'productTypeDes' },
    { name: '领取方式', label: 'receiveTypeDes' },
    { name: '修改日期', label: 'updateTime' }
  ]
}
